package com.leezt.designpattern.principles.OCP;

import com.leezt.designpattern.principles.OCP.handlers.ErrorAlertHandler;
import com.leezt.designpattern.principles.OCP.handlers.TpsAlertHandler;
import com.leezt.designpattern.principles.OCP.services.Alert;
import com.leezt.designpattern.principles.OCP.services.AlertNotificaton;
import com.leezt.designpattern.principles.OCP.services.AlertRuleManager;
import com.leezt.designpattern.principles.OCP.services.INotify;

public class ApplicationContext {
    private AlertRuleManager alertRuleMgr;
    private INotify notification;
    private Alert alert;

    public void initializeBeans() {
        alertRuleMgr = new AlertRuleManager(/*.省略参数.*/); //省略一些初始化代码
        notification = new AlertNotificaton(/*.省略参数.*/); //省略一些初始化代码
        alert = new Alert();
        alert.addAlertHandler(new TpsAlertHandler(alertRuleMgr, notification));
        alert.addAlertHandler(new ErrorAlertHandler(alertRuleMgr, notification));
    }
    public Alert getAlert() { return alert; }

    // 饿汉式单例
    private static final ApplicationContext instance = new ApplicationContext();
    private ApplicationContext() {
        initializeBeans();
    }
    public static ApplicationContext getInstance() {
        return instance;
    }
}
